package view;
import java.rmi.RemoteException;

import javax.swing.JFrame;

import server.FirewallSession;

import server.FirewallException;
import server.NotExpertException;
import server.ReadWriteException;
import server.Rule;
import server.FirewallSession;
import server.RulesTableType;

public class RulesAdvancedTable extends AbstractRulesTable
{
	/**
	 * 
	 */
	private static final long serialVersionUID = -3740562357093729559L;

	/* Column names */
	protected final static String columnNames[] = RuleTable.columnNames;
	
	/* Current advanced rules tables */
	public static RulesAdvancedTable currentInRulesAdvancedTable = null;
	public static RulesAdvancedTable currentOutRulesAdvancedTable = null;
	
	public RulesAdvancedTable(RulesTableType type,FirewallSession ui)
	{	    
		super(type, Settings.DEFAULT_RULES_WINDOW_DEPTH, columnNames.length,ui);
		
		switch(type)
		{
		case IN:
			currentInRulesAdvancedTable = this;
			break;
		case OUT:
			currentOutRulesAdvancedTable = this;
			break;
		}
		build();
	}
	
	/**
	 * Returns the table columns names
	 * @return - the table columns names
	 */
	protected String[] getColumnsNames() 
	{
		return columnNames;
	}
	
	/**
	 * @return - the user mode
	 */
	public String getUserMode()
	{
		return UserMode.advancedUser;
	}

	public void addRule(RulesTableType direction, Rule rule) {
		try {
			UI.addRule(direction, Settings.ruleset, rule);
		} catch (RemoteException e) {
			ErrorFrame.AddError("Failed to add the rule:" + e.getMessage(), new JFrame());
		} catch (FirewallException e) {
			ErrorFrame.AddError("Failed to add the rule:" + e.getMessage(), new JFrame());
		} catch (ReadWriteException e) {
			ErrorFrame.AddError("Failed to add the rule:" + e.getMessage(), new JFrame());
		} catch (NotExpertException e) {
			ErrorFrame.AddError("Failed to add the rule:" + e.getMessage(), new JFrame());
		}
		build();
	}
}


